/**
 * @team Dynamic Duo
 * 1. Maayan Keshet
 * 2. Gal Bitensky
 */

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import poland.Calc;
import poland.Expression;

class Main {
	public static void main(String[] args) {
		boolean flgError = false;
		BufferedReader br = null;

		if (args.length != 1) {
			System.out.println("Wrong number of arguments.");
			flgError = true;
		} else {
			try {
				br = new BufferedReader(new FileReader(args[0]));
			} catch (Exception e) {
				System.out.println("Error opening the specified file.");
				flgError = true;
			}
		}

		if (flgError) {
			System.out.println("Usage: java -cp bin Main <input-filename>");
			return;
		}

		Calc c = new Calc();
		String line;
		try {
			while ((line = br.readLine()) != null) {
				Expression res = null;

				try {
					res = c.process(line);
				} catch (Exception e) {
					flgError = true;
				}

				System.out.println(line
						+ " : "
						+ (flgError ? "invalid expression" : (res.toString()
								+ " = " + res.evaluate())));

				c.clearState();
				flgError = false;
			}
			br.close();
		} catch (IOException e) {
			System.out
					.println("IO error while reading file: " + e.getMessage());
		}
	}
}
